#!/usr/bin/env python
# Copyright (C) Kumo inc. and its affiliates.
# Author: Jeff.li lijippy@163.com
# All rights reserved.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https:#www.gnu.org/licenses/>.
#

[build-system]
requires = [
  "scikit-build-core>=0.10",
  "setuptools_scm[toml]>=8",
  "pyarrow",
  "pybind11",
]
build-backend = "scikit_build_core.build"

[project]
name = "pypollux"
dynamic = ["version"]
description = "Python bindings and extensions for Pollux"
readme = "README.md"
requires-python = ">=3.9"
license = "Apache-2.0"
authors = [{ name = "Meta", email = "pollux@fb.com" }]
maintainers = [{ name = "Meta", email = "pollux@fb.com" }]
dependencies = ["pyarrow"]
classifiers = [
  "Intended Audience :: Developers",
  "Intended Audience :: Science/Research",
  "Operating System :: POSIX :: Linux",
  "Programming Language :: C++",
  "Programming Language :: Python :: 3.9",
  "Programming Language :: Python :: 3.10",
  "Programming Language :: Python :: 3.11",
  "Programming Language :: Python :: 3.12",
  "Programming Language :: Python :: Implementation :: CPython",
]

[project.urls]
homepage = "https://github.com/facebookincubator/pollux"

[tool.scikit-build]
build-dir = "_build/python"
metadata.version.provider = "scikit_build_core.metadata.setuptools_scm"
ninja.make-fallback = false
install.components = ["pypollux_libraries"]
wheel.packages = ["python/pypollux"]
wheel.exclude = ["*.h*", "*.cpp", "CMakeLists.txt", "test/*"]

[tool.scikit-build.sdist]
include = ["scripts/setup-helper-functions.sh"]
exclude = [
  ".github/",
  "pollux/docs",
  "pollux/experimental",
  "website",
  "docs",
  "static",
  "scripts",
  "*.md",
  "ccache",
  "Makefile",
  "docker-compose.yml",
  "license.header",
  ".clang-format",
  ".cmake-format.yaml",
]

# TODO reuse of already build pollux with POLLUX_BUILD_DIR
[tool.scikit-build.cmake]
version = ">=3.28"
build-type = "Release"

[tool.scikit-build.cmake.define]
POLLUX_BUILD_PYTHON_PACKAGE = true
POLLUX_BUILD_SHARED = true
POLLUX_BUILD_TESTING = false
POLLUX_MONO_LIBRARY = true
TREAT_WARNINGS_AS_ERRORS = true
MAX_HIGH_MEM_JOBS = { env = "MAX_HIGH_MEM_JOBS", default = "" }
MAX_HIGH_LINK_JOBS = { env = "MAX_HIGH_LINK_JOBS", default = "" }

[[tool.scikit-build.overrides]]
if.env.DEBUG = true        # 1 maps to true
cmake.build-type = "Debug"

[[tool.scikit-build.overrides]]
# These settings are for use with signature verification in CI
if.env.POLLUX_PYTHON_LEGACY_ONLY = 'ON'
inherit.cmake.define = "append"
cmake.define.POLLUX_PYTHON_LEGACY_ONLY = true
cmake.define.POLLUX_BUILD_SHARED = false
cmake.define.POLLUX_ENABLE_ARROW = true

[[tool.scikit-build.overrides]]
# The pypollux cibw image compiler throws cpp 20 warnings we
# have yet to fix see #10866
if.env.CIBUILDWHEEL = true
inherit.cmake.define = "append"
cmake.define.TREAT_WARNINGS_AS_ERRORS = false

[tool.setuptools_scm]
root = '.'
version_scheme = 'guess-next-dev'
git_describe_command = 'git describe --dirty --tags --long --match "pypollux-v[0-9]*.*"'
fallback_version = '0.2.0a'

[tool.cibuildwheel]
build = "cp312-*"
skip = "*musllinux* cp36-* cp38-*"
archs = "native"
manylinux-x86_64-image = "ghcr.io/facebookincubator/pollux-dev:pypollux"
before-all = "ccache -sz"
before-test = "ccache -s"
test-command = "echo Tests disabled for now see #12836" #"python -m unittest discover -s {project}/python/test"

[tool.cibuildwheel.linux]
repair-wheel-command = """auditwheel repair \
                          --exclude 'libarrow*' \
                          --exclude 'libparquet*' \
                          --exclude 'libpollux*' \
                          -w {dest_dir} {wheel}\
                       """

[tool.cibuildwheel.macos]
# delocate skips the excluded libs instead of just ignoring it as a dependency
# see matthew-brett/delocate/issues/207
before-build = "pip install --upgrade git+https://github.com/assignUser/delocate@fix-exclude"
repair-wheel-command = """delocate-wheel \
                          --exclude 'libarrow' \
                          --exclude 'libparquet' \
                          --exclude 'libpollux' \
                          --require-archs {delocate_archs} \
                          -w {dest_dir} -v {wheel}\
                       """
